Imports System.Data
Imports System.Data.SqlClient

Partial Class GetClinicContract
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim cnnClinicContract As SqlConnection
        Dim cmdClinicContract As SqlCommand
        Dim rdClinicContract As SqlDataReader
        Try
            Try
                If Me.Request.Params("name") <> Nothing Then
                    If Not ((Session("uid") Is Nothing) Or (Session("pwd") Is Nothing) Or (Session("uid") = "") Or (Session("pwd") = "")) Then
                        Dim strConnectionString As String
                        Dim strResponse As String
                        Dim strControl As String
                        Dim strTargetControl As String
                        strControl = Me.Request.Params("name")
                        strTargetControl = Replace(Me.Request.Params("name"), "ddlClinic", "ddlClinicContract")

                        Me.Response.Clear()
                        strConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnection").ConnectionString & "uid=" & Session("uid").ToString & ";pwd=" & Session("pwd").ToString
                        cnnClinicContract = New SqlConnection
                        cnnClinicContract.ConnectionString = strConnectionString
                        cnnClinicContract.Open()
                        cmdClinicContract = New SqlCommand
                        cmdClinicContract.Connection = cnnClinicContract
                        cmdClinicContract.CommandType = CommandType.Text
                        If Me.Request.Params(strControl) <> Nothing Then
                            If Me.Request.Params("name").IndexOf("ddlClinic") >= 0 Then
                                'Me.Response.Write("<select name='" & strTargetControl & "' id='" & Replace(strTargetControl, "_", "&") & "' style='width:470px;'>")
                                cmdClinicContract.CommandText = "SELECT CLINIC_CONTRACT_ID,CONTRACT_ID FROM CLINIC_CONTRACT WHERE CLINIC_ID = " + Me.Request.Params(strControl).ToString
                                rdClinicContract = cmdClinicContract.ExecuteReader()
                                While rdClinicContract.Read
                                    strResponse = "<option value='" + rdClinicContract.GetInt32(0).ToString + "'>" + rdClinicContract.GetInt32(1).ToString + "</option>"
                                    Me.Response.Write(strResponse)
                                End While
                                'Me.Response.Write("</select>")
                            Else
                                'Me.Response.Write("<select name='" & strTargetControl & "' id='" & Replace(strTargetControl, "_", "&") & "' style='width:470px;'>")
                                'Me.Response.Write("</select>")
                            End If
                        Me.Response.End()
                        End If
                    End If
                End If
            Catch ex As SqlException
                Exit Sub
            End Try
        Finally
            If Not (rdClinicContract Is Nothing) Then
                rdClinicContract.Close()
                rdClinicContract = Nothing
            End If
            If Not (cnnClinicContract Is Nothing) Then
                cnnClinicContract.Close()
                cnnClinicContract = Nothing
            End If
            If Not (cmdClinicContract Is Nothing) Then
                cmdClinicContract.Dispose()
                cmdClinicContract = Nothing
            End If
        End Try
    End Sub
End Class
